#include <exception>

void __cdecl __ehvec_ctor( 
						  void * __p_a							// pointer to array
						  , unsigned int __size					// element size
						  , int __p_n							// number of elements
						  , void (__cdecl * __ctor)(void *)		// ctor
						  , void (__cdecl * __dtor)(void *))	// dtor
{
	//According to 15.2.2
	//destroying partial objects if constructor throws.
	void * __a = __p_a;
	int __n;

	try 
	{
		for( __n = 0; __n < __p_n; ++__n ) 
		{
			(*__ctor) (__a);
			__a = (char *) __a + __size;
		}
	} 
	catch( ... )
	{
		//Partial construction calling destructors
		::__ehvec_dtor( __p_a, __size, __n + 1, __dtor );
		throw;
	}
}

//eh vector destructor iterator( pA, sizeof(A), count, &A::~A);
void __cdecl __ehvec_dtor( void * __a, unsigned int __size, int __n, void (__cdecl*__dtor)(void *) )
{
	try {
		//Reverse order destruction
		__a = (char *) __a + __size * __n;
		while (-- __n >= 0 ) 
		{
			__a = (char *) __a - __size;
			(*__dtor) (__a);
		}
	} 
	catch(...)
	{
		//According to 15.2.3
		std::terminate();
	}
}